package fields;
import game.*;

public class TryYourLuck extends Field {
	
	private LuckyCardStack luckycards;
	
	public TryYourLuck(int number, String name, LuckyCardStack luckycards) {
		super(number, name);
		this.luckycards = luckycards;
	}
	
	public String fieldInfo(Player p) {
		return luckycards.pullCard().getSentence();
	}
		
	public void landOnField(Player p) {
		
		if (luckycards.pullCard().isOutOfJailCard()) {
			p.addOutOfJailCard();
			luckycards.removeCard();
		}
		else {
			p.deposit(luckycards.pullCard().getAmount());
			executeCommand(p);
			luckycards.putCardLast();
		}
	}
	
	private void executeCommand(Player p) {
		if (luckycards.pullCard().getCommand().equals("Move to jail")) {
			p.setInJail();
		} else if (luckycards.pullCard().getCommand().equals("Move to start")) {
			p.moveTo(1);
		} else if (luckycards.pullCard().getCommand().equals("Move to Grønningen")) {
			p.moveTo(25);
		} else if (luckycards.pullCard().getCommand().equals("Matador-scholarship")) {
			if (p.calculateTotalAssets()<15000) p.deposit(40000);
		} else if (luckycards.pullCard().getCommand().equals("Move three fields back")) {
			p.moveTo(p.getField()-3);
		} else if (luckycards.pullCard().getCommand().equals("Move three fields ahead")) {
			p.moveTo(p.getField()+3);
		} else if (luckycards.pullCard().getCommand().equals("Move to Rådhuspladsen")) {
			p.moveTo(40);
		}
	}
}
